<script>
	$(document).ready(function() {
		init_data();
		init_seq();
		init_add_link();
		$(".data.data_1").change(function() {
			calc_score();
		});

	});

	function init_data() {
		<volist name = "last_report_detail"	id = "vo" >		
		if({$key}>2){
			add_subject();
		}
		 $("input[name=subject]:eq({$key})").val("{$vo.subject}");

		$arr_item = "{$vo.item}".split("|||");
		$arr_start_time = "{$vo.start_time}".split("|||");
		$arr_end_time = "{$vo.end_time}".split("|||");
		$arr_status = "{$vo.status}".split("|||");
		
		$k = 0;
		for (var i in $arr_item) {
			console.log($arr_item[i]);
			if (i > 1) {
				$html = $("#sample_item").html();
				$(".work_content:eq({$key})").find("div.col-sm-8").append($html);
			}
			$(".work_content:eq({$key})").find("input[name=item]:eq(" + $k + ")").val($arr_item[i]);
			$(".work_content:eq({$key})").find("input[name=start_time]:eq(" + $k + ")").val($arr_start_time[i]);
			$(".work_content:eq({$key})").find("input[name=end_time]:eq(" + $k + ")").val($arr_end_time[i]);
			$(".work_content:eq({$key})").find("input[name=status]:eq(" + $k + ")").val($arr_status[i]);
			$k++;
		}
		</volist>
	}

	function init_seq() {

	}

	function init_add_link() {

	}

	function dec_add(num1, num2) {
		var reg = /\./i;
		if (!reg.test(num1) && !reg.test(num2)) {
			return parseInt(num1) + parseInt(num2);
		}
	}

	function calc_score() {
		$total = 0;
		$(".data.data_1").each(function() {
			if ($(this).val() !== '') {
				$total = dec_add($total, $(this).val());
			}
		});
		$(".data_total.data_1").val($total);
	}

	function init_input_name() {
		$row_count = 0;
		$("div.work_content").each(function() {
			$("input[name=subject]", this).attr('name', "subject[]");

			$("input[name=item]", this).each(function() {
				$(this).attr('name', "item_" + $row_count + "[]");
			});

			$("input[name=start_time]", this).each(function() {
				$(this).attr('name', "start_time_" + $row_count + "[]");
			});

			$("input[name=end_time]", this).each(function() {
				$(this).attr('name', "end_time_" + $row_count + "[]");
			});

			$("input[name=status]", this).each(function() {
				$(this).attr('name', "status_" + $row_count + "[]");
			});
			$row_count++;
		});
	}

	function add_subject() {
		$html = $("#sample_subject").html();
		$("#work_content").append($html);
	}

	function add_item($obj) {
		$html = $("#sample_item").html();
		$($obj).parents("div.col-sm-8").append($html);
	}

	function add_plan() {
		$html = $("#sample_plan").html();
		$("#plan").append($html);

	}
	
	function share($content){
		winopen("{:U('share')}",700,530);
	}

	function save($submit) {
		$('#is_submit').val($submit);
		init_input_name();
		window.onbeforeunload = null;
		if (check_form("form_data")) {
			sendForm("form_data", "{:U('save')}");
		}
	}

</script>
